package com.party.mobile.web.controller.file;

import com.google.common.collect.Maps;
import com.party.common.utils.PartyCode;
import com.party.common.utils.StringUtils;
import com.party.core.model.file.VideoResource;
import com.party.core.service.file.IVideoResourceService;
import com.party.mobile.web.dto.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 图片资源
 */
@Controller
@RequestMapping(value = "/file/video")
public class VideoResourceController {
    @Autowired
    IVideoResourceService videoResourceService;

    Logger logger = LoggerFactory.getLogger(getClass());


    @ResponseBody
    @RequestMapping(value = "getPreviewData")
    public AjaxResult getPreviewData(String id) {
        if (StringUtils.isEmpty(id)) {
            return AjaxResult.error(PartyCode.PARAMETER_ILLEGAL, "id不能为空");
        }
        try {
            VideoResource videoResource = videoResourceService.get(id);
            Map<String, Object> map = Maps.newHashMap();
            map.put("path", videoResource.getPath());
            map.put("posterUrl", videoResource.getPosterUrl());
            return AjaxResult.success(map);
        } catch (Exception e) {
            logger.error("获取视频资源异常", e);
            return AjaxResult.error(100, "获取视频资源异常");
        }
    }
}
